package org.feng.utils.redis;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author by feng
 * @des redisList
 * @date 2021/4/27 14:03
 */
@Component
public class RedisList extends RedisCommon {
    /**
     * 左入栈
     *
     * @param key
     * @param value
     */
    public RedisTemplate<Object, Object> leftPush(Object key, Object value) {
        redisTemplate.opsForList().leftPush(key, value);
        return super.redisTemplate;
    }

    /**
     * 右入栈
     *
     * @param key
     * @param value
     */
    public RedisTemplate<Object, Object> rightPush(Object key, Object value) {
        redisTemplate.opsForList().rightPush(key, value);
        return super.redisTemplate;
    }

    /**
     * 左出栈
     *
     * @param key
     * @return
     */
    public Object leftPop(Object key) {
        return redisTemplate.opsForList().leftPop(key);
    }

    /**
     * 右出栈
     *
     * @param key
     * @return
     */
    public Object rightPop(Object key) {
        return redisTemplate.opsForList().rightPop(key);
    }

    /**
     * 范围查询
     *
     * @param key
     * @param start
     * @param end
     * @return
     */
    public Object range(Object key, Long start, Long end) {
        return redisTemplate.opsForList().range(key, start, end);
    }

    /**
     * 位置查询
     *
     * @param key
     * @param index
     * @return
     */
    public Object index(Object key, Long index) {
        return redisTemplate.opsForList().index(key, index);
    }

    /**
     * 查询位置
     *
     * @param key
     * @param value
     * @return
     */
    public Long indexOf(Object key, Object value) {
        return redisTemplate.opsForList().indexOf(key, value);
    }

    /**
     * 查询最后一个位置
     *
     * @param key
     * @param value
     * @return
     */
    public Long lastIndexOf(Object key, Object value) {
        return redisTemplate.opsForList().lastIndexOf(key, value);
    }

    /**
     * 大小
     *
     * @param key
     * @return
     */
    public Long sizeList(Object key) {
        return redisTemplate.opsForList().size(key);
    }

    /**
     * 右全入栈
     *
     * @param key
     * @param list
     * @return
     */
    public Long rightPushAll(Object key, List<Object> list) {
        return redisTemplate.opsForList().rightPushAll(key, list);
    }
}
